import 'package:shared_preferences/shared_preferences.dart';
//token的获取与存储
class TokenManager {
  static const String _tokenKey = 'user_token';

  // 保存Token
  static Future<void> saveToken(String token) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_tokenKey, token);
  }

  // 获取Token
  static Future<String?> getToken() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_tokenKey);
  }

  // 清除Token
  static Future<void> clearToken() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    // await prefs.remove(_tokenKey);
    await prefs.setString(_tokenKey, "");
  }
//   // 保存Token
//   await TokenManager.saveToken('your_token');
//
// // 获取Token
//   String? token = await TokenManager.getToken();
//   print('Token: $token');
//
// // 清除Token
//   await TokenManager.clearToken();
}
//存储城市列表版本
class CityListVersionManager{
  static const String CityListVersion="0";

  // 保存城市列表版本
  static Future<void> saveCityListVersion(String citylistversion) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(CityListVersion as String, citylistversion as String);
  }

  // 获取城市列表版本
  static Future<String?> getCityListVersion() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(CityListVersion);
  }

  // 清除
  static Future<void> clearCityListVersion() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(CityListVersion);
  }
}
//存储城市列表
class CityListManager{
  static const String CityList="0";

  // 保存城市列表
  static Future<void> saveCityList(String citylist) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(CityList as String, citylist as String);
  }

  // 获取城市列表
  static Future<String?> getCityList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(CityList);
  }

  // 清除
  static Future<void> clearCityList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(CityList);
  }
}
//userId的获取与存储
class UserIdManager {
  static const String _userId = 'userID';

  // 保存
  static Future<void> saveUserID(String userId) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_userId, userId);
  }

  // 获取
  static Future<String?> getUserID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_userId);
  }

  // 清除
  static Future<void> clearUserID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(_userId);
  }
}
//手机号的获取与存储
class PhoneNumManager {
  static const String pnhonNum = 'Phone';

  // 保存
  static Future<void> savePhone(String phoneNum) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(pnhonNum, phoneNum);
  }

  // 获取
  static Future<String?> getPhone() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(pnhonNum);
  }

  // 清除
  static Future<void> clearPhone() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(pnhonNum);
  }
}
//IMId的获取与存储
class IMIdManager {
  static const String _IMId = 'IMID';

  // 保存
  static Future<void> saveIMID(String userId) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_IMId, userId);
  }

  // 获取
  static Future<String?> getIMID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_IMId);
  }

  // 清除
  static Future<void> clearIMID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(_IMId);
  }
}

//经度的获取与存储
class LongitudeManager {
  static const String _longitude = 'longitude';

  // 保存
  static Future<void> saveLongitude(String longitude) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_longitude, longitude);
  }

  // 获取
  static Future<String?> getLongitude() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_longitude);
  }

  // 清除
  static Future<void> clearLongitude() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_longitude, "");
  }
}
//纬度的获取与存储
class LatitudeManager {
  static const String _latitude = 'latitude';

  // 保存
  static Future<void> saveLatitude(String latitude) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_latitude, latitude);
  }

  // 获取
  static Future<String?> getLatitude() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_latitude);
  }

  // 清除
  static Future<void> clearLatitude() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_latitude, "");
  }
}
//历史地址
class HisCityManager {
  static const String _HisCitys = 'HisCitys';

  // 保存数组
  static Future<void> saveHisCitysList(List<String> hisCitysList) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setStringList(_HisCitys, hisCitysList);
  }

  // 获取数组
  static Future<List<String>> getHisCitysList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    List<String>? userIdList = prefs.getStringList(_HisCitys);
    return userIdList ?? [];
  }

  // 清除数组
  static Future<void> clearHisCitysList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(_HisCitys);
  }
}